package com.appengine.news.utils;

import java.util.logging.Level;
import java.util.logging.Logger;


/**
 * String utils
 * 
 * @author Aliaksandr_Spichakou
 * 
 */
public class StringUtils {
	private static final Logger log = Logger.getLogger(StringUtils.class
			.getName());
	/**
	 * Check empty string
	 * @param arg
	 * @return
	 */
	public static boolean isEmpty(String arg) {
		return (arg == null) || (arg.length() == 0);
	}
	/**
	 * Parse String to long
	 * @param arg
	 * @return
	 */
	public static Long parseString2Long(String arg)
	{
		if(StringUtils.isEmpty(arg))
		{
			log.log(Level.SEVERE, "Given string is empty");
			return null;
		}
		try {
			long parseLong = Long.parseLong(arg);
			return new Long(parseLong);
		} catch (Exception e) {
			log.log(Level.WARNING, "Given string is not Long", e);
		}
		return null;
	}
	
	/**
	 * Parse string to int 
	 * @param arg
	 * @return int or -1
	 */
	public static int parseString2Int(String arg)
	{
		if(StringUtils.isEmpty(arg))
		{
			log.log(Level.SEVERE, "Given string is empty");
			return -1;
		}
		try {
			int parseInt = Integer.parseInt(arg);
			return parseInt;
		} catch (Exception e) {
			log.log(Level.WARNING, "Given string is not ont", e);
		}
		return -1;
	}
}
